mod base {

trait Contains<A, B> {
    fn contains(&self, _: &A, _: &B) -> bool;
    fn first(&self) -> i32;
    fn last(&self) -> i32;
}




struct Container(i32, i32);
impl Contains<i32, i32> for Container {
    fn contains(&self, number_1: &i32, number_2: &i32) -> bool {
        (&self.0 == number_1) && (&self.1 == number_2)
    }
    fn first(&self) -> i32 { self.0 }
    fn last(&self) -> i32 { self.1 }
}

fn difference<A, B, C>(container: & C) -> i32 where 
    C: Contains<A, B> { //NOTE: explicit declare the associated types
    container.last() - container.first()
}

pub fn base() {
    let number_1 = 3;
    let number_2 = 10;
    println!("does container contain {} and {}", &number_1, &number_2);


    let container = Container(number_1, number_2);
    println!("container: {}", container.contains(&number_1, &number_2));
    println!("First number: {}", container.first());
    println!("Last number: {}", container.last());

    println!("The difference is: {}", difference(&container));
}

}//mod base

mod rewrite {


trait Contains {
    type A;
    type B;

    fn contains(&self, _: &Self::A, _: &Self::B) -> bool;
    fn first(&self) -> i32;
    fn last(&self) -> i32;
}

struct Container(i32, i32);
impl Contains for Container {
    type A = i32;
    type B = i32;

    fn contains(&self, number_1: &i32, number_2: &i32) -> bool {
        (&self.0 == number_1) && (&self.1 == number_2)
    }

    fn first(&self) -> i32 { self.0 }
    fn last(&self) -> i32 { self.1 }
}//impl Contains

//NOTE: no need to declare the associated type
fn difference<C: Contains>(container: &C) -> i32 {
    container.last() - container.first()
}

pub fn rewrite(){
    let number_1 = 3;
    let number_2 = 10;
    println!("Does container contain {} and {}", &number_1, &number_2);

    let container = Container(number_1, number_2);
    println!("Conainter: {}", container.contains(&number_1, &number_2));
    println!("First number: {}", container.first());
    println!("Last number: {}", container.last());

    println!("The difference is: {}", difference(&container));
}

}//mod rewrite

pub fn main(){
    self::base::base();
    self::rewrite::rewrite();
}
